/*
 * SensoryMemory.h
 *
 *  Created on: 2013-02-06
 *      Author: mathieu
 */

#ifndef SENSORYMEMORY_H_
#define SENSORYMEMORY_H_

#include "semol/core/SemolExp.h" // DLL export/import defines

#include "semol/core/Parameters.h"
#include "semol/core/Sensor.h"
#include <utilite/UStl.h>

class UColorTable;

namespace semol {

class SEMOL_EXP SensoryMemory {
public:
	SensoryMemory(const ParametersMap & parameters = ParametersMap());
	virtual ~SensoryMemory();

	void parseParameters(const ParametersMap & parameters);

	int add(Sensor::Type type, const cv::Mat & data);
	int add(const SensorRaw & sensor);

	void add(Sensor * sensor);
	void add(const std::map<int, Sensor *> & sensor);
	Sensor * remove(int id);

	void addSensorRef(int sensorId, int nodeId);
	void removeSensorRef(int sensorId, int nodeId);

	int size() const;
	const std::vector<std::map<int, Sensor*> > & getSensors() const {return _sensors;}
	const std::set<int> & getNotRefSensors() const {return _notRefSensors;}
	int getSimilaritySensorMapSize() const {return _similaritySensorMap.size();}
	const Sensor* getSensor(int id) const;
	bool contains(int id) const;

	void setLastSensorId(int id) {_lastSensorId = id;}

	void clear();

	float compare(int sensorA, int sensorB, bool * bufferedLookup = 0);

private:
	std::vector<float> computeImageDescriptor(const cv::Mat & image);
	std::vector<float> computeAudioDescriptor(const cv::Mat & audio);
	std::vector<float> computeTwistDescriptor(const cv::Mat & twist);

	float compare(const std::vector<float> & descriptorA, const std::vector<float> & descriptorB, Sensor::Type) const;

	cv::Mat audioToLog(const cv::Mat & audio);

private:
	float _audiodBThreshold;
	bool _audioLog;
	bool _audiodBIndexing;
	int _audioIgnoredDCComponents;
	float _audioCrop;
	float _audioMinMagnitude;
	unsigned int _twistDecimalResolution;
	bool _grayScale;

	int _lastSensorId;
	std::vector<std::map<int, Sensor*> > _sensors; // <type <id, Sensor> >
	std::map<int, Sensor::Type> _sensorsType; //<id, type>

	std::set<int> _notRefSensors;
	std::map<int, std::map<int, float> > _similaritySensorMap;
};

} /* namespace semol */
#endif /* SENSORYMEMORY_H_ */
